﻿var wcGood; //商品编号
var wcSpec; //规格
var wcColor;//色号

function wcGood_InitializeCombo(webComboId){
	wcGood = igcmbo_getComboById(webComboId);
	wcGood.getGrid().Bands[0].curTable=wcGood.getGrid().Element;  //设定默认Band
}
function wcSpec_InitializeCombo(webComboId){
	wcSpec = igcmbo_getComboById(webComboId);
	wcSpec.getGrid().Bands[0].curTable=wcSpec.getGrid().Element;  //设定默认Band
}
function wcColor_InitializeCombo(webComboId){
	wcColor = igcmbo_getComboById(webComboId);
	wcColor.getGrid().Bands[0].curTable=wcColor.getGrid().Element;  //设定默认Band
}

function wgMain_BeforeEnterEditModeHandler(gridName, cellId){
    if (igtbl_getCellById(cellId).Column.Key=="GoodID"){ //判断激活事件的列
        LoadGood(cellId)
    }    
    if (igtbl_getCellById(cellId).Column.Key=="Spec"){ //判断激活事件的列
        LoadSpec(cellId)
    }          	
    if (igtbl_getCellById(cellId).Column.Key=="Color"){ //判断激活事件的列
        LoadColor(cellId)
    }
}

function wgMain_AfterExitEditModeHandler(gridName, cellId){
    if (igtbl_getCellById(cellId).Column.Key=="GoodID"){ //判断激活事件的列
	    //igtbl_getCellById(cellId).Row.getCellFromKey("Price").setValue("89.00"); //Ajax取数据过程
	}
}

function LoadGood(cellId){
    wcGood.setDisplayValue("Re-Loading",false,false); 
  	
    Ajax.Good.GetGood(LoadGood_callback); //异步
}
function LoadGood_callback(response) { 
    while(wcGood.grid.Rows.length>0) {  //删除原有数据
        wcGood.grid.Rows.remove(0); 
    } 
    var ds = response.value;
    for(var i=0;i<ds.Tables[0].Rows.length;i++) { //构建新表格
        var row=wcGood.getGrid().Rows.addNew(); 
        row.getCell(0).setValue(ds.Tables[0].Rows[i].SubString); 
    } 
    wcSpec.setDisplayValue("",false,false); 
} 

function LoadSpec(cellId){
    wcSpec.setDisplayValue("Re-Loading",false,false); 
  	var goodid = igtbl_getCellById(cellId).Row.getCellFromKey("GoodID").getValue();
    Ajax.Good.GetGoodSpec(goodid,LoadSpec_callback); //异步
}
function LoadSpec_callback(response) { 
    while(wcSpec.grid.Rows.length>0) {  //删除原有数据
        wcSpec.grid.Rows.remove(0); 
    } 
    var ds = response.value;
    for(var i=0;i<ds.Tables[0].Rows.length;i++) { //构建新表格
        var row=wcSpec.getGrid().Rows.addNew(); 
        row.getCell(0).setValue(ds.Tables[0].Rows[i].SubString); 
    } 
    wcSpec.setDisplayValue("",false,false); 
} 

function LoadColor(cellId){
    wcColor.setDisplayValue("Re-Loading",false,false); 
  	var goodid = igtbl_getCellById(cellId).Row.getCellFromKey("GoodID").getValue();
    Ajax.Good.GetGoodColor(goodid,LoadColor_callback); //异步
}
function LoadColor_callback(response) { 
    while(wcColor.grid.Rows.length>0) {  //删除原有数据
        wcColor.grid.Rows.remove(0); 
    } 
    var ds = response.value;
    for(var i=0;i<ds.Tables[0].Rows.length;i++) { //构建新表格
        var row=wcColor.getGrid().Rows.addNew(); 
        row.getCell(0).setValue(ds.Tables[0].Rows[i].SubString); 
    } 
    wcColor.setDisplayValue("",false,false); 
}

function wgMain_BeforeRowUpdateHandler(gridName, rowId){
	alert(igtbl_getRowById(rowId).getCellFromKey("ID").getValue());//检验值
}

function btnAdd_onclick(){
    alert("ok");
    igtbl_addNew("wgMain", 0); //新增一行
    return false;
}
function btnDel_onclick(){
    //igtbl_deleteRow("wgMain",igtbl_getActiveRow().Id);//删除一行
}
